package com.tjetc.test.common;

import com.tjetc.test.constants.ResultCode;
import org.springframework.http.HttpStatusCode;

/**
 *
 * 通用结果处理类
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/9
 */
public class Result<T> {

    // 这个状态码 有两种处理方式 使用枚举或者使用接口常量
    private Integer code;
    private String message;
    private T data;
//    private long timestamp;


    public Result() {
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> ok() {
        return new Result<>(ResultCode.SUCCESS_CODE, "成功", null);
    }


    public static <T> Result<T> ok(T data) {
        return new Result<>(ResultCode.SUCCESS_CODE, "成功", data);
    }


    public static <T> Result<T> ok(String message, T data) {
        return new Result<>(ResultCode.SUCCESS_CODE, message, data);
    }


    public static <T> Result<T> fail() {
        return new Result<>(ResultCode.FAIL_CODE, "失败", null);
    }

    public static <T> Result<T> fail(String message, T data) {
        return new Result<>(ResultCode.FAIL_CODE, message, data);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<>(ResultCode.FAIL_CODE, "失败", data);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}